package com.walker.handler;

import java.io.Serializable;

import com.walker.util.CommonUtils;

import lombok.Data;
import net.sf.json.JSONObject;

@Data
public class ResponseData implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private boolean flag = false;
	
	private String msg = "";
	
	private Object data = null;
	
	private int totalRecords;
	
	public static ResponseData success(Object data,String msg) {
		ResponseData result = new ResponseData();
		result.setFlag(true);
		result.setMsg(msg);
		result.setData(data);
		return result;
	}
	
	public static ResponseData result(JSONObject json) {
		ResponseData result = new ResponseData();
		result.setFlag(json.getBoolean("flag"));
		result.setMsg(CommonUtils.valueOf(json.get("msg")));
		result.setData(json.get("data"));
		return result;
	}
	
	public static ResponseData success(String msg) {
		ResponseData result = new ResponseData();
		result.setFlag(true);
		result.setMsg(msg);
		return result;
	}
	
	public static ResponseData success(Object data) {
		ResponseData result = new ResponseData();
		result.setFlag(true);
		result.setData(data);
		return result;
	}
	
	public static ResponseData failure(String msg) {
		ResponseData result = new ResponseData();
		result.setFlag(false);
		result.setMsg(msg);
		return result;
	}
	
	public static ResponseData failure(Object data) {
		ResponseData result = new ResponseData();
		result.setFlag(false);
		result.setMsg("失败！");
		result.setData(data);
		return result;
	}
	
	public static ResponseData page(Object data,int totalRecords) {
		ResponseData result = new ResponseData();
		result.setFlag(true);
		result.setData(data);
		result.setMsg("成功！");
		result.setTotalRecords(totalRecords);
		return result;
	}
}